﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using System.Text;
using System.Data;
using System.Web.UI.HtmlControls;
using Aspose.Cells;

namespace MxWeiXinPF.Web.shopmgr.product
{
    public partial class productOnSale : MxWeiXinPF.Web.UI.ManagePage
    {
        protected MxWeiXinPF.Model.manager admin_info;
        private MxWeiXinPF.BLL.wx_shop_product caBll = new MxWeiXinPF.BLL.wx_shop_product();
        protected int catalogId = 0;
        protected int category_id;
        protected string keywords = string.Empty;
        protected int page;
        protected int pageSize;
        protected int shopid = 0;
        protected int totalCount;
        protected int selectshopid;

        private DataTable bindDate(int _category_id, string _strWhere)
        {
            if (_category_id > 0)
            {
                this.ddlCategoryId.SelectedValue = _category_id.ToString();
                _strWhere = _strWhere + " and categoryId=" + _category_id;
            }
            _strWhere = " upselling=1 " + _strWhere;
            MxWeiXinPF.BLL.wx_shop_product _product = new MxWeiXinPF.BLL.wx_shop_product();
            return _product.GetListForImport(_strWhere).Tables["ds"];
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int num = 0;
            int num2 = 0;
            for (int i = 0; i < this.rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)this.rptList.Items[i].FindControl("hidId")).Value);
                CheckBox box = (CheckBox)this.rptList.Items[i].FindControl("chkId");
                if (box.Checked)
                {
                    if (this.caBll.Delete(id))
                    {
                        num++;
                    }
                    else
                    {
                        num2++;
                    }
                }
            }
            base.AddAdminLog(MXEnums.ActionEnum.Delete.ToString(), string.Concat(new object[] { "删除商品信息", num, "条，失败", num2, "条" }));
            base.JscriptMsg(string.Concat(new object[] { "删除成功", num, "条，失败", num2, "条！" }), Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }), "Success");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            MxWeiXinPF.BLL.wx_shop_product _product = new MxWeiXinPF.BLL.wx_shop_product();
            Repeater rptList = this.rptList;
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int num3;
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                if (!int.TryParse(((TextBox)rptList.Items[i].FindControl("txtSortId")).Text.Trim(), out num3))
                {
                    num3 = 0x63;
                }
                _product.UpdateField(id, "sort_id=" + num3.ToString());
            }
            base.AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "保存出售中的商品内容排序");
            base.JscriptMsg("保存排序成功啦！", Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }), "Success");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.txtKeywords.Text, this.selectshopid.ToString() }));
        }

        protected void btnXiJia_Click(object sender, EventArgs e)
        {
            MxWeiXinPF.BLL.wx_shop_product _product = new MxWeiXinPF.BLL.wx_shop_product();
            Repeater rptList = this.rptList;
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox box = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (box.Checked)
                {
                    _product.UpdateField(id, "upselling=0");
                }
            }
            base.AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "下架出售中的商品");
            base.JscriptMsg("商品下架成功啦！", Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }), "Success");
        }

        protected string CombSqlTxt(string _keywords)
        {
            StringBuilder builder = new StringBuilder();
            _keywords = _keywords.Replace("'", "");
            if (!string.IsNullOrEmpty(_keywords))
            {
                builder.Append(" and  (isnull(productname,'')  like '%" + _keywords + "%' or  isnull(sku,'')  like '%" + _keywords + "%'  or isnull(zhunzi,'')  like '%" + _keywords + "%' or  isnull(wareid,'')  like '%" + _keywords + "%') ");
            }
            //if (this.admin_info != null)
            //{
            //    builder.Append(" and shopid=" + this.admin_info.id + " ");
            //}
            //else
            //{
            //    this.admin_info = base.GetAdminInfo();
            //    builder.Append(" and shopid=" + this.admin_info.id + " ");
            //}
            if (this.selectshopid == 0) //店铺全选状态
            {
                Model.manager weixin = base.GetAdminInfo();
                if (weixin.agentLevel == 0)  //普通店铺
                {
                    int tempshopid = 0;
                    if (GetRelativeAdminInfo() != null)
                    {
                        tempshopid = GetRelativeAdminInfo().id;
                    }
                    else
                    {
                        tempshopid = GetAdminInfo().id;
                    }

                    if (weixin.id == 39 || tempshopid == 39) //管理员
                    {

                    }
                    else //普通店铺
                    {
                        builder.AppendFormat(" and shopid =" + tempshopid);
                    }
                }
                else //代理店铺
                {

                    builder.Append(" and shopid in (");
                    foreach (ListItem x in this.ddlShops.Items)
                    {
                        if (x.Value != "0")
                        {
                            builder.Append(x.Value);
                            builder.Append(",");
                        }
                    }
                    builder = builder.Remove(builder.Length - 1, 1);
                    builder.Append(") ");
                    // strTemp.AppendFormat(" shopid =" + selectshopid);
                }
            }
            else
            {
                builder.AppendFormat(" and shopid =" + selectshopid);
            }



            return builder.ToString();
        }

        protected void ddlCategoryId_SelectedIndexChanged(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.ddlCategoryId.SelectedValue, this.keywords, this.selectshopid.ToString() }));
        }
        protected void ddlShops_SelectedIndexChanged(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords, this.ddlShops.SelectedValue }));
        }
        protected void FillTableOld(Worksheet sheet, DataTable dt)
        {
            int num = 1;
            int num2 = 1;
            foreach (DataRow row in dt.Rows)
            {
                sheet.Cells[num2, 0].PutValue(dt.Rows[num - 1][0].ToString());
                sheet.Cells[num2, 1].PutValue(dt.Rows[num - 1][1].ToString());
                sheet.Cells[num2, 2].PutValue(dt.Rows[num - 1][2].ToString());
                sheet.Cells[num2, 3].PutValue(dt.Rows[num - 1][3].ToString());
                sheet.Cells[num2, 4].PutValue(dt.Rows[num - 1][4].ToString());
                sheet.Cells[num2, 5].PutValue(dt.Rows[num - 1][5].ToString());
                sheet.Cells[num2, 6].PutValue(dt.Rows[num - 1][6].ToString());
                sheet.Cells[num2, 7].PutValue(dt.Rows[num - 1][7].ToString());
                sheet.Cells[num2, 8].PutValue(dt.Rows[num - 1][8].ToString());
                sheet.Cells[num2, 9].PutValue(dt.Rows[num - 1][9].ToString());
                sheet.Cells[num2, 10].PutValue(dt.Rows[num - 1][10].ToString());
                sheet.Cells[num2, 11].PutValue(dt.Rows[num - 1][9].ToString());
                sheet.Cells[num2, 12].PutValue(dt.Rows[num - 1][10].ToString());
                num++;
                num2++;
            }
        }

        private int GetPageSize(int _default_size)
        {
            int num;
            if (int.TryParse(Utils.GetCookie("productOnSale_page_size"), out num) && (num > 0))
            {
                return num;
            }
            return _default_size;
        }

        protected void lbtnExport_Click(object sender, EventArgs e)
        {
            try
            {

                if (this.admin_info != null)
                {
                    this.shopid = this.admin_info.id;
                }
                else
                {
                    this.admin_info = base.GetAdminInfo();
                    this.shopid = this.admin_info.id;
                }
                int num = 0;
                if (!this.ddlCategoryId.SelectedValue.Equals(""))
                {
                    num = int.Parse(this.ddlCategoryId.SelectedValue);
                }
                Workbook workbook = new Workbook(base.Server.MapPath("../../upload/xlstep/shopproduct.xls"));
                int count = workbook.Worksheets.Count;
                Worksheet sheet = workbook.Worksheets[0];
                Cell cell = sheet.Cells[0, 0];
                DataTable dt = this.bindDate(num, this.CombSqlTxt(this.txtKeywords.Text.ToString().Trim()));
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    this.FillTableOld(sheet, dt);
                    workbook.RemoveMacro();
                    XlsSaveOptions saveOptions = new XlsSaveOptions
                    {
                        SaveFormat = SaveFormat.Excel97To2003
                    };
                    string s = this.shopid.ToString() + "-" + DateTime.Now.ToString("yyyy-MM-dd") + this.ddlCategoryId.SelectedItem.Text + "出售商品表.xls";
                    workbook.Save(base.Response, base.Server.UrlEncode(s), ContentDisposition.Attachment, saveOptions);
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(base.GetType(), "asd", "<script>alert('没有符合条件的记录！');</script>");
                }

            }
            catch (Exception ex)
            {

            }
        }

        protected void lbtnImport_Click(object sender, EventArgs e)
        {
            try
            {

                if (this.admin_info != null)
                {
                    this.shopid = this.admin_info.id;
                }
                else
                {
                    this.admin_info = base.GetAdminInfo();
                    this.shopid = this.admin_info.id;
                }
                int num = 0;
                if (!this.ddlCategoryId.SelectedValue.Equals(""))
                {
                    num = int.Parse(this.ddlCategoryId.SelectedValue);
                }
                Workbook workbook = new Workbook(base.Server.MapPath("../../upload/xlstep/shopproduct.xls"));
                int count = workbook.Worksheets.Count;
                Worksheet sheet = workbook.Worksheets[0];
                Cell cell = sheet.Cells[0, 0];
                DataTable dt = this.bindDate(num, this.CombSqlTxt(this.txtKeywords.Text.ToString().Trim()));
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    this.FillTableOld(sheet, dt);
                    workbook.RemoveMacro();
                    XlsSaveOptions saveOptions = new XlsSaveOptions
                    {
                        SaveFormat = SaveFormat.Excel97To2003
                    };
                    string s = this.shopid.ToString() + "-" + DateTime.Now.ToString("yyyy-MM-dd") + this.ddlCategoryId.SelectedItem.Text + "商品表.xls";
                    workbook.Save(base.Response, base.Server.UrlEncode(s), ContentDisposition.Attachment, saveOptions);
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(base.GetType(), "asd", "<script>alert('没有符合条件的记录！');</script>");
                }

            }
            catch (Exception ex)
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.keywords = MXRequest.GetQueryString("keywords");
                this.category_id = MXRequest.GetQueryInt("category_id");
                this.pageSize = this.GetPageSize(10);
                this.selectshopid = MXRequest.GetQueryInt("selectshopid");
                if (!this.Page.IsPostBack)
                {
                    this.admin_info = base.GetAdminInfo();
                    this.btnDelete.Visible = ChkAdminLevelEx("onlineproduct", MXEnums.ActionEnum.Edit.ToString());
                    this.btnXiJia.Visible = btnDelete.Visible;
                    btnSave.Visible = btnDelete.Visible;
                    this.TreeBind();
                    this.TreeBindShops();
                    this.RptBind(this.category_id, this.CombSqlTxt(this.keywords), "sort_id asc,id desc");
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void RptBind(int _category_id, string _strWhere, string _orderby)
        {
            if (this.category_id > 0)
            {
                this.ddlCategoryId.SelectedValue = _category_id.ToString();
            }
            if (this.selectshopid > 0)
            {
                this.ddlShops.SelectedValue = this.selectshopid.ToString();
            }
            else
            {
                this.ddlShops.SelectedValue = "0";
            }

            _strWhere = "  upselling=1   " + _strWhere;
            //MxWeiXinPF.Model.manager weiXinCode = base.GetAdminInfo();
            int num15 = 0;
            if (GetRelativeAdminInfo() != null)
            {
                num15 = GetRelativeAdminInfo().id;
            }
            else
            {
                num15 = GetAdminInfo().id;
            }

            this.lblWid.Text = num15.ToString();
            this.page = MXRequest.GetQueryInt("page", 1);
            this.txtKeywords.Text = this.keywords;

            DataSet set = this.caBll.GetListEx(this.category_id, this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            this.rptList.DataSource = set;
            this.rptList.DataBind();
            this.txtPageNum.Text = this.pageSize.ToString();
            string linkUrl = Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&page={2}&selectshopid={3}", new string[] { _category_id.ToString(), this.keywords, "__id__", this.selectshopid.ToString() });
            this.PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, linkUrl, 8);
        }

        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidId")).Value);
            MxWeiXinPF.BLL.wx_shop_product _product = new MxWeiXinPF.BLL.wx_shop_product();
            MxWeiXinPF.Model.wx_shop_product model = _product.GetModel(id);
            string commandName = e.CommandName;
            if (commandName != null)
            {
                if (!(commandName == "lbtnIslatest"))
                {
                    if (commandName == "lbtnIshotsale")
                    {
                        if (model.hotsale)
                        {
                            _product.UpdateField(id, "hotsale=0");
                        }
                        else
                        {
                            _product.UpdateField(id, "hotsale=1");
                        }
                    }
                    else if (commandName == "lbtnIsspecialOffer")
                    {
                        if (model.specialOffer)
                        {
                            _product.UpdateField(id, "specialOffer=0");
                        }
                        else
                        {
                            _product.UpdateField(id, "specialOffer=1");
                        }
                    }
                }
                else if (model.latest)
                {
                    _product.UpdateField(id, "latest=0");
                }
                else
                {
                    _product.UpdateField(id, "latest=1");
                }
            }
            this.RptBind(this.category_id, this.CombSqlTxt(this.keywords), "sort_id asc,id desc");
        }

        protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Literal literal = e.Item.FindControl("litlatest") as Literal;
                Literal literal2 = e.Item.FindControl("lithotsale") as Literal;
                Literal literal3 = e.Item.FindControl("litspecialOffer") as Literal;
                if (literal.Text.ToLower() == "true")
                {
                    literal.Text = " <img alt=\"\" src=\"../../images/yes.gif\" />";
                }
                else
                {
                    literal.Text = " <img alt=\"\" src=\"../../images/no.gif\" />";
                }
                if (literal2.Text.ToLower() == "true")
                {
                    literal2.Text = " <img alt=\"\" src=\"../../images/yes.gif\" />";
                }
                else
                {
                    literal2.Text = " <img alt=\"\" src=\"../../images/no.gif\" />";
                }
                if (literal3.Text.ToLower() == "true")
                {
                    literal3.Text = " <img alt=\"\" src=\"../../images/yes.gif\" />";
                }
                else
                {
                    literal3.Text = " <img alt=\"\" src=\"../../images/no.gif\" />";
                }
            }
        }

        private void TreeBind()
        {
            try
            {
                MxWeiXinPF.Model.manager weiXinCode = base.GetAdminInfo();

                DataTable wCodeList = new MxWeiXinPF.BLL.wx_shop_category().GetWCodeList(39, 0);
                this.ddlCategoryId.Items.Clear();
                this.ddlCategoryId.Items.Add(new ListItem("所有类别", ""));
                foreach (DataRow row in wCodeList.Rows)
                {
                    string str = row["id"].ToString();
                    int num = int.Parse(row["class_layer"].ToString());
                    string text = row["title"].ToString().Trim();
                    if (num == 1)
                    {
                        this.ddlCategoryId.Items.Add(new ListItem(text, str));
                    }
                    else
                    {
                        text = "├ " + text;
                        text = Utils.StringOfChar(num - 1, "　") + text;
                        this.ddlCategoryId.Items.Add(new ListItem(text, str));
                    }
                }
            }
            catch (Exception ex)
            {
                
            }

        }

        private void TreeBindShops()
        {
            try
            {
                BLL.manager bll = new BLL.manager();
                Model.manager weixin = base.GetAdminInfo();
                DataSet set = new DataSet();
                if (weixin.agentLevel == 0)
                {
                    if (weixin.id == 39)
                    {
                        set = bll.GetList(-1, " ", "");
                    }
                    else
                    {
                        if (weixin.relativeid != 0)
                        {
                            set = bll.GetList(-1, "", "");
                        }
                        else {
                            set = bll.GetList(-1, " id= " + weixin.id, "");
                        }
                        
                    }
                }
                else
                {
                    if (weixin.agentLevel == 1)
                    {
                        set = bll.GetListByCounty(string.IsNullOrEmpty(weixin.county) ? 0 : int.Parse(weixin.county));
                    }
                    else if (weixin.agentLevel == 2)
                    {
                        set = bll.GetListByCity(string.IsNullOrEmpty(weixin.city) ? 0 : int.Parse(weixin.city));
                    }
                    else if (weixin.agentLevel == 3)
                    {
                        set = bll.GetListByProvince(string.IsNullOrEmpty(weixin.province) ? 0 : int.Parse(weixin.province));
                    }
                    else
                    {
                        return;
                    }
                }
                this.ddlShops.Items.Clear();
                this.ddlShops.Items.Add(new ListItem("所有店铺", "0"));
                foreach (DataRow row in set.Tables[0].Rows)
                {
                    if (row["id"].ToString() == this.selectshopid.ToString())
                    {
                        ddlShops.SelectedValue = row["id"].ToString();
                    }
                    this.ddlShops.Items.Add(new ListItem(row["real_name"].ToString(), row["id"].ToString()));
                }
                foreach (DataRow row in set.Tables[0].Rows)
                {
                    if (row["id"].ToString() == this.selectshopid.ToString())
                    {
                        ddlShops.SelectedValue = row["id"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        protected void txtPageCount_TextChanged(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&page={2}&selectshopid={3}", new string[] { this.category_id.ToString(), this.txtKeywords.Text, this.txtPageCount.Text.Trim(),this.selectshopid.ToString() }));
        }

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int num;
            if (int.TryParse(this.txtPageNum.Text.Trim(), out num) && (num > 0))
            {
                Utils.WriteCookie("productOnSale_page_size", num.ToString(), 0x3840);
            }
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }));
        }

        //导入上级
        protected void btnSync_Click(object sender, EventArgs e)
        {
            try
            {

                Model.manager weixin = GetAdminInfo();
                BLL.manager bman = new BLL.manager();
                Model.manager parent = bman.GetModel(weixin.parentid);
                if (parent == null || parent.id == weixin.id)
                {
                    base.JscriptMsg("没有上级！", Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }), "Success");
                    return;
                }
                string _strWhere = " a.ShopID=" + parent.id + " "; //上级商品数据
                List<Model.wx_shop_product> cats = caBll.GetModelList(_strWhere);
                if (cats == null || cats.Count == 0)
                {
                    base.JscriptMsg("上级没有数据可供同步！", Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords, this.selectshopid.ToString() }), "Success");
                    return;
                }
                initJavascript();
                _strWhere = " a.ShopID=" + weixin.id + " ";
                List<Model.wx_shop_product> cats2 = caBll.GetModelList(_strWhere);
                BLL.wx_shop_albums bblums = new BLL.wx_shop_albums();
                List<Model.wx_shop_albums> blums = bblums.GetModelList("");
                foreach (var item in cats)
                {
                    Model.wx_shop_product resultUser = cats2.Find(delegate(Model.wx_shop_product user)
                    {
                        return user.catalogId.Equals(item.catalogId) && user.categoryId == item.categoryId && user.productName == item.productName;
                    });
                    List<Model.wx_shop_albums> tempblums = blums.Where(x => x.productId == item.id).ToList<Model.wx_shop_albums>();
                    if (resultUser == null) //如果现有数据库中没找到相同的,则加入
                    {
                        item.wid = 39;
                        item.shopid = weixin.id;
                        int productid = caBll.Add(item);

                        foreach (Model.wx_shop_albums b2 in tempblums)
                        {
                            b2.productId = productid;
                            bblums.Add(b2);
                        }
                    }
                }
                UnloadJavascript();
                base.JscriptMsg("导入成功！", Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords,this.selectshopid.ToString() }), "Success");

            }
            catch (Exception ex)
            {

            }
        }

        public string GetShopName(int shopid)
        {
            Model.manager mm = new BLL.manager().GetModel(shopid);
            if (mm != null)
            {
                return mm.real_name;
            }
            return "";
        }

        #region "页面加载中效果"
        /// <summary>
        /// 页面加载中效果
        /// </summary>
        public void initJavascript()
        {
            HttpContext.Current.Response.Write(" <script language=JavaScript type=text/javascript>");
            HttpContext.Current.Response.Write("var t_id = setInterval(animate,20);");
            HttpContext.Current.Response.Write("var pos=0;var dir=2;var len=0;");
            HttpContext.Current.Response.Write("function animate(){");
            HttpContext.Current.Response.Write("var elem = document.getElementById('progress');");
            HttpContext.Current.Response.Write("if(elem != null) {");
            HttpContext.Current.Response.Write("if (pos==0) len += dir;");
            HttpContext.Current.Response.Write("if (len>32 || pos>79) pos += dir;");
            HttpContext.Current.Response.Write("if (pos>79) len -= dir;");
            HttpContext.Current.Response.Write(" if (pos>79 && len==0) pos=0;");
            HttpContext.Current.Response.Write("elem.style.left = pos;");
            HttpContext.Current.Response.Write("elem.style.width = len;");
            HttpContext.Current.Response.Write("}}");
            HttpContext.Current.Response.Write("function remove_loading() {");
            HttpContext.Current.Response.Write(" this.clearInterval(t_id);");
            HttpContext.Current.Response.Write("var targelem = document.getElementById('loader_container');");
            HttpContext.Current.Response.Write("targelem.style.display='none';");
            HttpContext.Current.Response.Write("targelem.style.visibility='hidden';");
            HttpContext.Current.Response.Write("}");
            HttpContext.Current.Response.Write("</script>");
            HttpContext.Current.Response.Write("<style>");
            HttpContext.Current.Response.Write("#loader_container {text-align:center; position:absolute; top:40%; width:100%; left: 0;}");
            HttpContext.Current.Response.Write("#loader {font-family:Tahoma, Helvetica, sans; font-size:11.5px; color:#000000; background-color:#FFFFFF; padding:10px 0 16px 0; margin:0 auto; display:block; width:130px; border:1px solid #5a667b; text-align:left; z-index:2;}");
            HttpContext.Current.Response.Write("#progress {height:5px; font-size:1px; width:1px; position:relative; top:1px; left:0px; background-color:#8894a8;}");
            HttpContext.Current.Response.Write("#loader_bg {background-color:#e4e7eb; position:relative; top:8px; left:8px; height:7px; width:113px; font-size:1px;}");
            HttpContext.Current.Response.Write("</style>");
            HttpContext.Current.Response.Write("<div id=loader_container>");
            HttpContext.Current.Response.Write("<div id=loader>");
            HttpContext.Current.Response.Write("<div align=center>页面正在加载中 </div>");
            HttpContext.Current.Response.Write("<div id=loader_bg><div id=progress> </div></div>");
            HttpContext.Current.Response.Write("</div></div>");
            HttpContext.Current.Response.Flush();
        }
        public void UnloadJavascript()
        {
            HttpContext.Current.Response.Write(" <script language=JavaScript type=text/javascript>");
            HttpContext.Current.Response.Write("remove_loading();");
            HttpContext.Current.Response.Write(" </script>");
        }
        #endregion
    }
}